﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;
using System.Collections;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueEnumerationTestFixture
    {
        public class EnumStructure
        {
            public TestEnum Value { get; set; }
        }

        public enum TestEnum : int
        {
            Zero = 0,
            One = 1,
            Four = 4,
            Eight = 8
        }

        [Test]
        public void StringTest()
        {
            var sourceOne = new
            {
                Value = "Four"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, TestEnum.Four);
        }

        [Test]
        public void StringNoMatchTest()
        {
            var sourceOne = new
            {
                Value = "FourTest"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void IntTest()
        {
            var sourceOne = new
            {
                Value = (int)4
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, TestEnum.Four);
        }

        [Test]
        public void IntNoMatchTest()
        {
            var sourceOne = new
            {
                Value = (int)14
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void ShortTest()
        {
            var sourceOne = new
            {
                Value = (short)4
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void BooleanZeroMatchTest()
        {
            var sourceOne = new
            {
                Value = new { Test = true }
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void BooleanTypeWrongTest()
        {
            var sourceOne = new
            {
                Value = new { One = "" }
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void BooleanOneMatchFalseTest()
        {
            var sourceOne = new
            {
                Value = new { One = false }
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, default(TestEnum));
        }

        [Test]
        public void BooleanOneMatchTrueTest()
        {
            var sourceOne = new
            {
                Value = new { One = true }
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, TestEnum.One);
        }

        [Test]
        public void BooleanTwoMatchTest()
        {
            var sourceOne = new
            {
                Value = new { One = true, Four = true }
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            EnumStructure enumStructure = ObjectToValue.Copy<EnumStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(enumStructure.Value, TestEnum.Four);
        }
    }
}
